package org.jianfa.homework.mail.controller;

import org.jianfa.homework.mail.service.EmailSerivce;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class EmailController {

    private static final Logger logger = LoggerFactory.getLogger(EmailController.class);

    @Autowired
    private EmailSerivce emailSerivce;

    @PostMapping("/mail/sendEmail")
    public boolean  sendEmail(@RequestParam("email") String email,
                            @RequestParam("code") String code) {
        try {
            emailSerivce.sendMail(email, "验证码", code);
            return true;
        } catch (Exception ex) {
            logger.error("发送验证码失败", ex);
            return false;
        }
    }
}
